#@head("设置菜单权限")
#define main()
#end
<body>
	<div class="layui-form" lay-filter="layuiadmin-form-system" id="layuiadmin-form-system" style="padding: 20px 20px 0 0;">
		<div class="layui-form-item">
			<div id="role-menu-tree"></div>
		</div>
		<input type="hidden" id="mIds" name="mIds" />
		<div class="layui-form-item layui-hide">
			<input type="button" lay-submit lay-filter="LAY-role-auth-front-submit" id="LAY-role-auth-front-submit" value="确认">
		</div>
	</div>
	#@layui()
	#define use()
		use(["index", "form", "tree"], function(){
			var $ = layui.$,
			form = layui.form,
			tree = layui.tree;
			
			//var ids = new Array();
			tree.render({
				elem: "#role-menu-tree",
				data: #(rootList??),
				showCheckbox: true,  //是否显示复选框
				id: "menu-tree",
				oncheck: function(obj){
					getCheckData();
				}
			});
			
			tree.setChecked("menu-tree", [#(menuIds??)]);
			getCheckData();
			
			function getJsonValue(result, obj, name){
				var value = "";
				for(var key in obj){
					value = obj[key];
					if(key == name){
						var index = result.indexOf(value);
						if (index == -1) {
							result.push(value);
						}
					} else {
						if(typeof value == "object"){
							result.concat(getJsonValue(result, value, name));
						}
					}
				}
				return result;
			}
			
			function getCheckData(){
				var checkedData = tree.getChecked("menu-tree");
				var ids = new Array();
				var array = getJsonValue(ids, checkedData, "id");
				$("#mIds").val(array.sort().join(","));
			}
		})
	#end
</body>
</html>